const BaseUrl = "http://localhost:8082"
const myquery = function(options){
	const url = BaseUrl + options.url
	const method = options.method || 'GET'
	const data = options.data || {}
	
	return new Promise ((resolve, reject) => {
		 return uni.request({
			url,
			method,
			data,
			success: res => {
				resolve(res)
			},
			fail: err => {
				uni.showToast({
					title:"数据获取失败"
				})
				return reject(err)
			}
			
		})
	})
}


const baseURL =  'http://152.136.185.210:7878/api/m5'
const swiperList = function (options) {
	const url =  baseURL + options.url
	return new Promise((resolve, reject) => {
		return uni.request({
			url,
			method: options.method || "GET",
			data: options.data || {},
			//成功的回调
			success: (res) => {
				resolve(res)
			},
			//失败的回调
			fail: (err) => {
				uni.showToast({
					title:"获取数据失败",
					icon:err
				})
				reject(err)
			}
		})
	})
}

const getGoodsList = function (options) {
	return new Promise ((resolve, reject) => {
		return uni.request({
			url: baseURL + options.url,
			method: options.method || "GET",
			success(res) {
				resolve(res)
				console.log(res)
			},
			fail(err) {
				uni.showToast({
					title:"获取商品列表失败",
					icon:err
				})
				reject(err)
			}
			
		})
	})
}

//获取分类数据
const getCategory = function (options) {
	
	return new Promise((resolve, reject) => {
		console.log(baseURL + options.url)
		return uni.request({
			url:baseURL + options.url,
			
			success:(data) =>{ 
				resolve(data)
			},
			fail:(err) => {
				reject(err)
				uni.showToast({
					title:'获取分类数据失败!',
					icon:err
				})
			}
			
		})
	})
}

//获取分类详情
const getCategoryDetail = function (options) {
	return new Promise((resolve, reject) => {
		return uni.request({
			url: baseURL + options.url,
			success(res) {
				resolve(res)
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

module.exports = {
	myquery,
	swiperList,
	getGoodsList,
	getCategory,
	getCategoryDetail
}